package com.ruoyi.web.controller.aggregation;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.aggregation.IStatisticsService;

/**
 * 数据统计Controller
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/agg/statistics")
public class StatisticsController
{
    @Autowired
    private IStatisticsService statisticsService;

    /**
     * 首页数据统计
     * 返回：商家数量、用户数量、业务员数量、订单数量等
     */
    @GetMapping("/home")
    public AjaxResult home()
    {
        try
        {
            Map<String, Object> data = statisticsService.getHomeStatistics();
            return AjaxResult.success(data);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 贡献值柱状图数据
     * 返回各区域代理的商家数量、业务员数量
     */
    @GetMapping("/contribution")
    public AjaxResult contribution()
    {
        try
        {
            Map<String, Object> data = statisticsService.getContributionStatistics();
            return AjaxResult.success(data);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 订单统计
     */
    @GetMapping("/order")
    public AjaxResult order()
    {
        try
        {
            Map<String, Object> data = statisticsService.getOrderStatistics();
            return AjaxResult.success(data);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 分佣统计
     */
    @GetMapping("/commission")
    public AjaxResult commission()
    {
        try
        {
            Map<String, Object> data = statisticsService.getCommissionStatistics();
            return AjaxResult.success(data);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }
}

